package com.niit.search.service.impl;

import com.niit.search.entity.Activity;
import com.niit.search.mapper.ActivityMapper;
import com.niit.search.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Collections;

@Service
public class ActivityServiceImpl implements ActivityService {
    private static final Logger logger = LoggerFactory.getLogger(ActivityServiceImpl.class);
    
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public List<Activity> searchActivity(String keyword) {
        return activityMapper.searchActivityByKeyword(keyword);
    }
    
    @Override
    public List<Activity> findActivitiesByTopicId(Long topicId) {
        if (topicId == null || topicId <= 0) {
            logger.warn("无效的话题ID: {}", topicId);
            return Collections.emptyList();
        }
        
        try {
            logger.info("查询话题ID为{}的相关动态", topicId);
            return activityMapper.findActivitiesByTopicId(topicId);
        } catch (Exception e) {
            logger.error("查询话题相关动态时发生错误: {}", e.getMessage(), e);
            return Collections.emptyList();
        }
    }
}